/************************权限资源管理js*********************************/
define(function(require, exports, module) {
	
	var $ = require("jquery1.7");
	var utils = require("utils");
	var ctx = utils.constants.ctx;
	var Validator = require("validator");
	var ui = require("ui");
	var BlackBox = require("blackbox");
	var blackBox = new BlackBox();
	var webTrendService=require("bean/webTrendService");
	
	//初始表格
	var table = layui.table;
	var tablelin = table.render({
		  elem: '#demo'
			    ,url : '/back/website/webTrendsData'
			    ,cols: [[ //标题栏
			      {checkbox:true, fixed: true}
			      ,{field: 'index', title: '序号', width: 80}
			      ,{field: 'title', title: '动态标题', width: 400}
			      ,{field: 'publisher', title: '发布人', width: 100}			     
			      ,{field: 'newTime', title: '发布时间', width: 150}			    
			      ,{field: '', title: '操作', width: 300,templet:'#barDemo'}
			    ]] 
			    ,even: true
			    ,page: true //是否显示分页
			    ,limits: [5, 10, 15,20,25,30]
			    ,limit: 5 //每页默认显示的数量
			    ,id: "test"
			  });
	
	//重载表格事件
	$(document).on("click","#searchBtn",function(){		
		var param = {
				title:$("#search_input").val()
		}
		tablelin.reload({
			where:param
		});
	})
	
	//添加动态
	$("#addWebTrendsBtn").bind("click",function(){
		location.href = ctx + "/back/website/webTrendsUpdate";
	});
	
	//删除

		$("#delWebTrendsBtn").bind("click", function(){
	        var checkStatus = layui.table.checkStatus('test');
			if (checkStatus.data.length===0) {
				layer.alert("请选择至少一条动态");
				return;
			}
			layer.confirm("确定要删除这些动态？",{icon: 3, title:'提示'},function(isOk){
				if(isOk){
					var data = checkStatus.data;
					var array = [];
					for(var i = 0; i<data.length;i++){
						array.push(data[i].id);   
					}
					if (array.length != 0) {
						try{
							ui.mask().show("请稍候...");
							webTrendService.delWebTrendsList(array);
							ui.mask().hide();
							layer.alert("删除成功",function(){
								
								window.location.reload(true);
							});
						} catch (e) {
							ui.mask().hide();
							layer.alert("删除失败:"+e.message);
						}
					}
				}
			})
		});
	
	//修改动态内容
	$(document).on("click",".updateWebTrends",function(){
		var id=$(this).attr("data").replace("webTrends_","");
		location.href=ctx + "/back/website/webTrendsUpdate?id="+id;
	});
	
	
	//详细页
	$(document).on("click",".checkWebTrendsDetail",function(){
		var id=$(this).attr("data").replace("webTrends_","");
		window.open("/back/website/checkWebTrendsDetail/"+id, "_blank");
	});
});

